import requests
import re
import os
import shutil

if os.path.exists('static/高清壁纸图片'):
	shutil.rmtree('static/高清壁纸图片')
os.mkdir('static/高清壁纸图片')

if os.path.exists('static/高清壁纸高级图片'):
	shutil.rmtree('static/高清壁纸高级图片')
os.mkdir('static/高清壁纸高级图片')


url = 'https://www.hdbz.net'
header = {
	'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36',
}

response = requests.get(url,headers=header)
datil_data = response.content.decode('utf8')
data_info = re.findall(r'<a href="(/wallpaper/\d{6}/\d{6}.html)" target="_blank" title="(.*?)".*?<img.*?data-original="(.*?)".*?class="lazy" />.*?</a>',datil_data,re.S)
for data in data_info:
	gaoqin_url = url + data[0]
	title = data[1]
	img_url = data[2]
	with open(f'static/高清壁纸图片/{title}.jpg','wb') as f:
		img_response = requests.get(img_url,headers=header)
		f.write(img_response.content)
	gaoqin_response = requests.get(gaoqin_url,headers=header)
	gaoqin_data = gaoqin_response.content.decode('utf8')
	# print(gaoqin_data)
	img_info = re.findall(r'<div class="pic-preview">.*?src="(.*?)" />.*?</div>',gaoqin_data,re.S)
	# print(img_info)
	for img in img_info:
		with open(f'static/高清壁纸高级图片/{title}.jpg','wb') as f:
			img_response = requests.get(img,headers=header)
			f.write(img_response.content)

